import store from '@/store/index.js'
module.exports = (vm) => {

	// 初始化请求配置
	uni.$u.http.setConfig((config) => {

		/* 根域名 */
		config.baseURL = 'http://testapp.xuexiluxian.cn';
		return config
	})

	// 请求拦截
	uni.$u.http.interceptors.request.use((config) => {
		if (store?.state?.user?.token) {
			config.header['Authorization'] = store?.state?.user?.token;
		}

		return config;
	}, config => {
		return Promise.reject(config);
	})

	// 响应拦截
	uni.$u.http.interceptors.response.use((response) => {
		const data = response.data;
		return data.data === undefined ? {} : data.data
	}, (response) => {
		return Promise.reject(response);
	})
}